﻿using Quartz;
using Quartz.Impl;
using Quartz.Logging;
using System;
using System.Threading.Tasks;

namespace QuartzNetTest
{
    class Program
    {
        static async Task Main( string[] args )
        {
            var provider = new ConsoleLogProvider();
            LogProvider.SetCurrentLogProvider(provider);
            //获取调度实例
            var factory = new StdSchedulerFactory();
            var scheduler = await factory.GetScheduler();
            provider.GetLogger("获取调度实例");

            //开始
            await scheduler.Start();
            //休眠60s
            IJobDetail job1= JobBuilder.Create<HelloJob>()
                .WithIdentity("job1", "group1")
                .Build();

            IJobDetail job2 = JobBuilder.Create<DumbJob>()
                .WithIdentity("job2","group1")
                .UsingJobData("jobsays","hello world!")
                .UsingJobData("myFloat",3.14f)
                .Build();

            ITrigger trigger = TriggerBuilder.Create().WithIdentity("trigger1", "group1")
                .StartNow()
                .WithSimpleSchedule(x => x.WithIntervalInSeconds(10)
                .RepeatForever())
                .Build();

            await scheduler.ScheduleJob(job2,trigger);

            await Task.Delay(TimeSpan.FromSeconds(60));

            await scheduler.Shutdown();
            provider.GetLogger("");
            Console.ReadKey();
        }
    }
}
